/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sft.Autenticacao.perfil.GUI;

import java.awt.HeadlessException;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import sft.Autenticacao.perfil.PerfilControle;
import sft.Autenticacao.perfil.logica.PerfilAcesso;
import sft.Principal.Principal;


public class JIPerfil extends javax.swing.JInternalFrame {
    
    private static Principal t;
    public JIPerfil(Principal p) {
        t = p;
        initComponents();
        iniciarComponentes();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jPProducao = new javax.swing.JPanel();
        jCPart = new javax.swing.JCheckBox();
        jCGlos = new javax.swing.JCheckBox();
        jCInco = new javax.swing.JCheckBox();
        jCCort = new javax.swing.JCheckBox();
        jCDesc = new javax.swing.JCheckBox();
        jPCadastro = new javax.swing.JPanel();
        jCConv = new javax.swing.JCheckBox();
        jCnCon = new javax.swing.JCheckBox();
        jCUnid = new javax.swing.JCheckBox();
        jCAten = new javax.swing.JCheckBox();
        jCConvDePara = new javax.swing.JCheckBox();
        jPAdministrador = new javax.swing.JPanel();
        jCPerfil = new javax.swing.JCheckBox();
        jCUsuario = new javax.swing.JCheckBox();
        jCMenu1 = new javax.swing.JCheckBox();
        jCMenu2 = new javax.swing.JCheckBox();
        jCMenu3 = new javax.swing.JCheckBox();
        jPanel7 = new javax.swing.JPanel();
        jBAdicionar = new javax.swing.JButton();
        jBEditar = new javax.swing.JButton();
        jBExcluir = new javax.swing.JButton();
        jBCancelar = new javax.swing.JButton();
        jBNovo = new javax.swing.JButton();
        jScrollTabela = new javax.swing.JScrollPane();
        jTTabela = new javax.swing.JTable();
        jScrollTabela = new javax.swing.JScrollPane();
        jTTabela.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        lsmTabela = jTTabela.getSelectionModel();
        lsmTabela.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    jTTabelaLinhaSelecionada(jTTabela);
                }
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Perfil de Acesso"));
        jPanel1.setAutoscrolls(true);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Descrição");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField1)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jPProducao.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Producao")));
        jPProducao.setPreferredSize(new java.awt.Dimension(150, 150));

        jCPart.setText("Particular");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu1, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCPart, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jCGlos.setText("Glosa");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu1, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCGlos, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jCInco.setText("Inconcistência");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu1, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCInco, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jCCort.setText("Cortesias");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu1, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCCort, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jCDesc.setText("Descontos");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu1, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCDesc, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout jPProducaoLayout = new javax.swing.GroupLayout(jPProducao);
        jPProducao.setLayout(jPProducaoLayout);
        jPProducaoLayout.setHorizontalGroup(
            jPProducaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPProducaoLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(jPProducaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCDesc)
                    .addComponent(jCCort)
                    .addComponent(jCInco)
                    .addComponent(jCGlos)
                    .addComponent(jCPart))
                .addContainerGap(55, Short.MAX_VALUE))
        );
        jPProducaoLayout.setVerticalGroup(
            jPProducaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPProducaoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCInco)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCGlos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCPart)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCCort)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCDesc)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPCadastro.setBorder(javax.swing.BorderFactory.createTitledBorder("Cadastro"));
        jPCadastro.setPreferredSize(new java.awt.Dimension(150, 122));

        jCConv.setText("Convênio");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu2, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCConv, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jCnCon.setText("Não Conformidade");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu2, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCnCon, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jCUnid.setText("Unidade");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu2, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCUnid, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jCAten.setText("Atendente");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu2, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCAten, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jCConvDePara.setText("DePara de Convênio");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu2, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCConvDePara, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout jPCadastroLayout = new javax.swing.GroupLayout(jPCadastro);
        jPCadastro.setLayout(jPCadastroLayout);
        jPCadastroLayout.setHorizontalGroup(
            jPCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPCadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCAten)
                    .addComponent(jCUnid)
                    .addComponent(jCnCon)
                    .addComponent(jCConv)
                    .addComponent(jCConvDePara))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPCadastroLayout.setVerticalGroup(
            jPCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPCadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCAten)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCUnid)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCnCon)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCConv)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCConvDePara)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPAdministrador.setBorder(javax.swing.BorderFactory.createTitledBorder("Administrador"));
        jPAdministrador.setPreferredSize(new java.awt.Dimension(150, 122));

        jCPerfil.setText("Perfil");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu3, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCPerfil, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jCUsuario.setText("Usuario");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jCMenu3, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jCUsuario, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout jPAdministradorLayout = new javax.swing.GroupLayout(jPAdministrador);
        jPAdministrador.setLayout(jPAdministradorLayout);
        jPAdministradorLayout.setHorizontalGroup(
            jPAdministradorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPAdministradorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPAdministradorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCPerfil)
                    .addComponent(jCUsuario))
                .addContainerGap(81, Short.MAX_VALUE))
        );
        jPAdministradorLayout.setVerticalGroup(
            jPAdministradorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPAdministradorLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCUsuario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCPerfil)
                .addContainerGap(74, Short.MAX_VALUE))
        );

        jCMenu1.setText("Menu");
        jCMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCMenu1ActionPerformed(evt);
            }
        });

        jCMenu2.setText("Menu");
        jCMenu2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCMenu2ActionPerformed(evt);
            }
        });

        jCMenu3.setText("Menu");
        jCMenu3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCMenu3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCMenu1)
                    .addComponent(jPProducao, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, 0)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCMenu2)
                    .addComponent(jPCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, 0)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCMenu3)
                    .addComponent(jPAdministrador, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jPAdministrador, jPCadastro, jPProducao});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCMenu1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jCMenu2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jCMenu3, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPProducao, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPCadastro, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPAdministrador, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel7.setDoubleBuffered(false);

        jBAdicionar.setText("Adicionar");
        jBAdicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAdicionarActionPerformed(evt);
            }
        });

        jBEditar.setText("Editar");
        jBEditar.setEnabled(false);
        jBEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEditarActionPerformed(evt);
            }
        });

        jBExcluir.setText("Excluir");
        jBExcluir.setEnabled(false);
        jBExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBExcluirActionPerformed(evt);
            }
        });

        jBCancelar.setText("SAIR");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        jBNovo.setText("Novo");
        jBNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNovoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBAdicionar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBEditar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBExcluir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jBNovo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBCancelar)
                .addContainerGap())
        );

        jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBAdicionar, jBEditar, jBExcluir});

        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBAdicionar)
                    .addComponent(jBEditar)
                    .addComponent(jBExcluir)
                    .addComponent(jBCancelar)
                    .addComponent(jBNovo))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollTabela.setPreferredSize(new java.awt.Dimension(200, 402));

        jTTabela.setModel(tmTabela);
        jScrollTabela.setViewportView(jTTabela);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollTabela, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollTabela, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(41, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
        // TODO add your handling code here:
        if(t == null){
           t = new Principal(); 
        }
        t.PerfilClose();
        dispose();
    }//GEN-LAST:event_jBCancelarActionPerformed

    private void jBNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBNovoActionPerformed
        // TODO add your handling code here:
        iniciarComponentes();
    }//GEN-LAST:event_jBNovoActionPerformed

    private void jCMenu2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCMenu2ActionPerformed
        // TODO add your handling code here:
        if(!jCMenu2.isSelected()){
            jCAten.setSelected(false);
            jCUnid.setSelected(false);
            jCConv.setSelected(false);
            jCnCon.setSelected(false);
            jCConvDePara.setSelected(false);
        }
            
    }//GEN-LAST:event_jCMenu2ActionPerformed

    private void jCMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCMenu1ActionPerformed
        // TODO add your handling code here:
        if(!jCMenu1.isSelected()){
            jCInco.setSelected(false);
            jCGlos.setSelected(false);
            jCPart.setSelected(false);
            jCCort.setSelected(false);
            jCDesc.setSelected(false);
        }
    }//GEN-LAST:event_jCMenu1ActionPerformed

    private void jBAdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAdicionarActionPerformed
        // TODO add your handling code here:
        cadastrar();
    }//GEN-LAST:event_jBAdicionarActionPerformed

    private void jCMenu3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCMenu3ActionPerformed
        // TODO add your handling code here:
        if(!jCMenu3.isSelected()){
            jCPerfil.setSelected(false);
            jCUsuario.setSelected(false);
        }
    }//GEN-LAST:event_jCMenu3ActionPerformed

    private void jBEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEditarActionPerformed
        // TODO add your handling code here:
        editar();
    }//GEN-LAST:event_jBEditarActionPerformed

    private void jBExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBExcluirActionPerformed
        deletar();
    }//GEN-LAST:event_jBExcluirActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAdicionar;
    private javax.swing.JButton jBCancelar;
    private javax.swing.JButton jBEditar;
    private javax.swing.JButton jBExcluir;
    private javax.swing.JButton jBNovo;
    private javax.swing.JCheckBox jCAten;
    private javax.swing.JCheckBox jCConv;
    private javax.swing.JCheckBox jCConvDePara;
    private javax.swing.JCheckBox jCCort;
    private javax.swing.JCheckBox jCDesc;
    private javax.swing.JCheckBox jCGlos;
    private javax.swing.JCheckBox jCInco;
    private javax.swing.JCheckBox jCMenu1;
    private javax.swing.JCheckBox jCMenu2;
    private javax.swing.JCheckBox jCMenu3;
    private javax.swing.JCheckBox jCPart;
    private javax.swing.JCheckBox jCPerfil;
    private javax.swing.JCheckBox jCUnid;
    private javax.swing.JCheckBox jCUsuario;
    private javax.swing.JCheckBox jCnCon;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPAdministrador;
    private javax.swing.JPanel jPCadastro;
    private javax.swing.JPanel jPProducao;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollTabela;
    private javax.swing.JTable jTTabela;
    private javax.swing.JTextField jTextField1;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    //Iniciar Variaveis
    private DefaultTableModel tmTabela = new DefaultTableModel(null, new String[] {"Descricao"});
    private ListSelectionModel lsmTabela;
    List<PerfilAcesso> list;
    //Finalizar Variaveis

    private void iniciarComponentes() {
        jTextField1.setText("");
        jCMenu1.setSelected(false);
        jCMenu2.setSelected(false);
        jCMenu3.setSelected(false);
        jCInco.setSelected(false);
        jCGlos.setSelected(false);
        jCPart.setSelected(false);
        jCCort.setSelected(false);
        jCDesc.setSelected(false);
        jCAten.setSelected(false);
        jCConv.setSelected(false);
        jCConvDePara.setSelected(false);
        jCUnid.setSelected(false);
        jCnCon.setSelected(false);
        jCPerfil.setSelected(false);
        jCUsuario.setSelected(false);
        jBEditar.setEnabled(false);
        jBExcluir.setEnabled(false);
        listarTabela();
    }

    private void cadastrar() {
        PerfilAcesso p = setaObjeto(new PerfilAcesso());
        PerfilControle ctrl = new PerfilControle();
        ctrl.Adicionar(p);
        informacao("Adionado");
        
    }
    
    private void editar() {
        PerfilAcesso p = setaObjeto(new PerfilAcesso());
        p.setId(list.get(jTTabela.getSelectedRow()).getId());
        PerfilControle ctrl = new PerfilControle();
        ctrl.Editar(p);
        informacao("Editado");
    }
    
    private void deletar() throws HeadlessException {
        // TODO add your handling code here:
        PerfilAcesso p = new PerfilAcesso();
        p.setId(list.get(jTTabela.getSelectedRow()).getId());
        PerfilControle ctrl = new PerfilControle();
        ctrl.Deletar(p);
        informacao("Deletado");
    }
    
    private void listarTabela() {
        PerfilControle ctrl = new PerfilControle();
        list = ctrl.getList(new PerfilAcesso(), false);        
        mostrarTabela();
    }

    private void mostrarTabela() {
        while(tmTabela.getRowCount() > 0){
            tmTabela.removeRow(0);
        }
        if(list.isEmpty()){
            //se a lista for vazia.
        }else{
            String[] linha = new String[]{null};
            for (int i = 0; i < list.size(); i++) {
                tmTabela.addRow(linha);
                tmTabela.setValueAt(list.get(i).getNome(), i, 0);
            }
        }
    }
    
    public void jTTabelaLinhaSelecionada(JTable jTTabela){
        if(jTTabela.getSelectedRow() != -1){
            liberaMenu(jTTabela);
            jCAten.setSelected(list.get(jTTabela.getSelectedRow()).isCad_aten());
            jCConv.setSelected(list.get(jTTabela.getSelectedRow()).isCad_conv());
            jCConvDePara.setSelected(list.get(jTTabela.getSelectedRow()).isCad_conv_depara());
            jCnCon.setSelected(list.get(jTTabela.getSelectedRow()).isCad_ncon());
            jCUnid.setSelected(list.get(jTTabela.getSelectedRow()).isCad_unid());
            jCPerfil.setSelected(list.get(jTTabela.getSelectedRow()).isCad_perfil());
            jCUsuario.setSelected(list.get(jTTabela.getSelectedRow()).isCad_usua());
            jCGlos.setSelected(list.get(jTTabela.getSelectedRow()).isProd_glos());
            jCInco.setSelected(list.get(jTTabela.getSelectedRow()).isProd_inco());
            jCPart.setSelected(list.get(jTTabela.getSelectedRow()).isProd_part());
            jCCort.setSelected(list.get(jTTabela.getSelectedRow()).isProd_cort());
            jCDesc.setSelected(list.get(jTTabela.getSelectedRow()).isProd_desc());
            jTextField1.setText(list.get(jTTabela.getSelectedRow()).getNome());
            jBEditar.setEnabled(true);
            jBExcluir.setEnabled(true);
        }
    }

    private void liberaMenu(JTable jTTabela) {
        if(list.get(jTTabela.getSelectedRow()).isProd_inco() || 
                list.get(jTTabela.getSelectedRow()).isProd_glos() || 
                list.get(jTTabela.getSelectedRow()).isProd_part() ||
                list.get(jTTabela.getSelectedRow()).isProd_cort() ||
                list.get(jTTabela.getSelectedRow()).isProd_desc()){
            
            jCMenu1.setSelected(true);
        }
        if(list.get(jTTabela.getSelectedRow()).isCad_aten() || 
                list.get(jTTabela.getSelectedRow()).isCad_conv() || 
                list.get(jTTabela.getSelectedRow()).isCad_ncon() || 
                list.get(jTTabela.getSelectedRow()).isCad_unid() ||
                list.get(jTTabela.getSelectedRow()).isCad_conv_depara()){
            
            jCMenu2.setSelected(true);
        }
        if(list.get(jTTabela.getSelectedRow()).isCad_usua() || 
                list.get(jTTabela.getSelectedRow()).isCad_perfil()){
            
            jCMenu3.setSelected(true);
        }
    }

    private PerfilAcesso setaObjeto(PerfilAcesso p) {
        
        p.setNome(jTextField1.getText());
        p.setCad_aten(jCAten.isSelected());
        p.setCad_conv(jCConv.isSelected());
        p.setCad_ncon(jCnCon.isSelected());
        p.setCad_unid(jCUnid.isSelected());
        p.setProd_glos(jCGlos.isSelected());
        p.setProd_inco(jCInco.isSelected());
        p.setProd_part(jCPart.isSelected());
        p.setCad_usua(jCUsuario.isSelected());
        p.setCad_perfil(jCPerfil.isSelected());
        p.setProd_cort(jCCort.isSelected());
        p.setProd_desc(jCDesc.isSelected());
        p.setCad_conv_depara(jCConvDePara.isSelected());
        return p;
        
    }
    private void informacao(String informacao) throws HeadlessException {
        JOptionPane.showMessageDialog(null, informacao + " com sucesso!","Atenção",JOptionPane.INFORMATION_MESSAGE);
        iniciarComponentes();
    }

    

}
